package com.longkey.workflow.client.selector
{
	import flash.events.Event;
	
	import spark.components.BorderContainer;
	import spark.components.CheckBox;
	import spark.components.gridClasses.GridItemRenderer;
	import spark.layouts.VerticalLayout;
	
	public class CheckBoxColumnHeadRender extends GridItemRenderer
	{
		private var checkAll:CheckBox;
		private var changeHandleFunc:Function;
		override public function prepare(hasBeenRecycled:Boolean):void
		{
			super.prepare(hasBeenRecycled);
			var col:CheckBoxGridColumn = this.column as CheckBoxGridColumn;
			this.checkAll.selected = col.selectAll;
			this.checkAll.addEventListener(Event.CHANGE, checkBoxChangeHandle);
		}
		
		private function checkBoxChangeHandle(event:Event):void{
			var col:CheckBoxGridColumn = this.column as CheckBoxGridColumn;
			col.selectAll = this.checkAll.selected;
			if(this.changeHandleFunc != null){
				this.changeHandleFunc(this.checkAll.selected);
			}
		}
		
		public function set changeHandle(func:Function):void{
			this.changeHandleFunc = func;
		}
		
		
		public function CheckBoxColumnHeadRender(){
			var vl:VerticalLayout = new VerticalLayout();
			vl.horizontalAlign = "center";
			vl.verticalAlign = "middle";
			this.layout = vl;
			this.checkAll = new CheckBox();
			this.addElement(this.checkAll);
		}
	}
}